package com.capacitacion.service.impl;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import com.capacitacion.model.User;
import com.capacitacion.service.HelloService;



/**
 * Session Bean implementation class HelloServiceImpl
 */
@Stateless
public class HelloServiceImpl implements HelloService {

 @PersistenceContext(unitName = "toursUnit")
 EntityManager em;

 public HelloServiceImpl() {
 }

 @Override
 public User login(String username, String password) {
  Query query = em
    .createQuery("select u from User u where u.username = :username and u.password = :password");
  query.setParameter("username", username);
  query.setParameter("password", password);
  
  List<User> result = query.getResultList();
  
  if (result != null && result.size() > 0) {
   return result.get(0); //first user
  }
  return null;
 }

}
